<?php
declare (strict_types=1);

namespace app\controller;

use app\BaseController;
use app\common\Common;
use app\model\Banner;
use app\model\Message;
use app\model\User;
use Endroid\QrCode\Color\Color;
use Endroid\QrCode\QrCode;
use Endroid\QrCode\Writer\PngWriter;

class IndexController extends BaseController
{
	
	function index()
	{
		$writer = new PngWriter();
		$qrCode = QrCode::create('11111')//跳转的url地址
		->setSize(100)      //大小
		->setMargin(0)             //边距
		->setForegroundColor(new Color(0, 0, 0))        //前景色
		->setBackgroundColor(new Color(255, 255, 255));       //背景色
		$result = $writer->write($qrCode)->getDataUri();
		dd($result);
	}
	
	/**
	 * 轮播图
	 * @return void
	 */
	function banner()
	{
		$rows = Banner::order(['weigh' => 'desc'])->select();
		$this->writeJson($rows);
	}
	
	function message()
	{
		$rows = Message::order(['weigh' => 'desc'])->limit(5)->select();
		$this->writeJson($rows);
	}
	
	function messageDetail()
	{
		$id = $this->request->get('id/d');
		$row = Message::findOrFail($id);
		$this->writeJson($row);
	}
	
	
}
